package com.howard.modules.base.paging;

public class Paging {
	private int currentPage;
	private int pageSize;//每页记录数
	private int records;//总记录数
	private int prePage;
	private int nextPage;
	private int pageCount;//总页数
	private static final int FIRST_PAGE = 1;
	private static final int DEFAULT_PAGE_SIZE = 20;
	
	public int getPageCount() {
	    int pageSize = this.getPageSize();
		if(records%pageSize == 0){
			pageCount = records/pageSize;
		}else{
			pageCount = (records/pageSize) + 1;
		}
		return pageCount;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		if(pageSize == 0){
			pageSize = DEFAULT_PAGE_SIZE;
		}
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRecords() {
		return records;
	}

	public void setRecords(int records) {
		this.records = records;
	}

	public int getPrePage() {
		prePage = currentPage - 1;
		if(prePage <= FIRST_PAGE){
			prePage = FIRST_PAGE;
		}
		return prePage;
	}
	
	public int getNextPage() {
		nextPage = currentPage + 1;
		if(nextPage >= this.getPageCount()){
			nextPage = pageCount;
		}
        if(nextPage < FIRST_PAGE){
            this.nextPage = FIRST_PAGE;
        }
		return nextPage;
	}

	public boolean isFirst(){
		return  currentPage <= FIRST_PAGE ;
	}
	
	public boolean isLast(){
		return currentPage >= pageCount;
	}
	
	public int getStartRow(){
		if(currentPage >= 1){
			return (currentPage-1)*getPageSize() ;
		}else{
			return 1;
		}
	}


}
